package net.neptech.controller;

import lombok.RequiredArgsConstructor;
import net.neptech.model.sys.Position;
import net.neptech.page.PageQuery;
import net.neptech.page.TableDataInfo;
import net.neptech.service.PositionService;
import net.neptech.utils.BeanCopyUtils;
import net.neptech.vm.ResponseResult;
import net.neptech.vo.PositionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liyuxiang
 * @Date: 2025/8/18 15:13
 * @Description: 职称接口
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/position")
public class PositionController {
    @Autowired
    private PositionService positionService;

    @GetMapping("list")
    public TableDataInfo<PositionVo> list(Position position, PageQuery pageQuery) {
        TableDataInfo<PositionVo> tableDataInfo = positionService.selectPositionListPage(position, pageQuery);
        return tableDataInfo;
    }

    @GetMapping("listPage")
    public TableDataInfo<PositionVo> listPage(Position position, PageQuery pageQuery) {
        TableDataInfo<PositionVo> tableDataInfo = positionService.selectPositionListPage(position, pageQuery);
        return tableDataInfo;
    }

    /**
     * 添加岗位
     */
    @PostMapping("")
    public ResponseResult<Void> insertPosition(@RequestBody Position position) {
        positionService.insertPosition(position);
        return ResponseResult.success();
    }
    /**
     * 获取岗位详情
     */
    @GetMapping("{positionId}")
    public ResponseResult<PositionVo> getPositionById(@PathVariable Long positionId) {
        PositionVo position = positionService.getPositionById(positionId);
        return ResponseResult.success(position);
    }
    /**
     * 删除岗位
     */
    @DeleteMapping("{positionIds}")
    public ResponseResult<Void> deletePositionById(@PathVariable Long[] positionIds) {
        positionService.deletePositionByIds(positionIds);
        return ResponseResult.success();
    }
    /**
     * 更新岗位信息
     */
    @PutMapping("")
    public ResponseResult<Void> updatePosition(@RequestBody Position position) {
        positionService.updatePosition(position);
        return ResponseResult.success();
    }
}
